import 'package:aichat_flutter_wallet/module/module_browser/viewmodel/before_browser.dart';
import 'package:aichat_flutter_wallet/module/module_dapp/model/dapp_hot_model.dart';
import 'package:aichat_flutter_wallet/module_common/widgets/skeleton/dapp_top_item_skeleton.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lib_network/http_config.dart';
import 'package:lib_network/http_manager.dart';
import 'package:lib_util/log/log.dart';
import '../../../../module_common/bridge/native_channel_bridge.dart';
import '../../../../module_common/network/http_api.dart';
import '../../../../module_common/router/routers.dart';
import '../../provider/dapp_provider.dart';
import '../dapp_empty.dart';
import '../dapp_title.dart';
import '../dapp_top_item.dart';
import 'package:lib_util/lib_util.dart';

class DAppHotComp extends StatefulWidget {
  const DAppHotComp({
    super.key,
  });

  @override
  _DAppHotCompState createState() => _DAppHotCompState();
}

class _DAppHotCompState extends State<DAppHotComp> {
  bool _testhidden = true;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      padding: EdgeInsets.only(bottom: 0),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.bottomCenter,
          end: Alignment.topCenter,
          colors: [
            Color.fromRGBO(255, 255, 255, 1),
            Color.fromRGBO(255, 255, 255, 0.1)
          ],
        ),
      ),
      child: Consumer<DAppProvider>(builder: (context, provider, child) {
        return Column(
          children: [
            DAppTitle(
              title: 'Hot',
              showHotIcon: true,
              showMore: true,
              isLoading: provider.isLoading,
              onClick: () {
                Routes.router!.navigateTo(context, Routes.dAppHotRoute);
              },
            ),
            Column(
              children: [
                if (!provider.isLoading && provider.hotList.length > 0)
                  Container(
                      margin: const EdgeInsets.only(
                        left: 20,
                      ),
                      padding: const EdgeInsets.only(top: 8, bottom: 2),
                      height: 80.w,
                      child: ListView.builder(
                          itemCount: provider.hotList.length > 8
                              ? 8
                              : provider.hotList.length,
                          scrollDirection: Axis.horizontal,
                          itemBuilder: (BuildContext context, int index) {
                            var item = provider.hotList[index];

                            return DAppTopiItem(
                                statement: item.bookmark.statement,
                                onClick: () {
                                  WebSiteInfoItem webSiteInfoItem =
                                      WebSiteInfoItem(
                                          websiteUrl: item.bookmark.url,
                                          websiteImg: item.bookmark.logo,
                                          websiteName: item.bookmark.name,
                                          websiteTag: item.bookmark.statement);
                                  doGotoBrowser(
                                      context: context,
                                      webUrl: item.bookmark.url,
                                      isSearchIn: false,
                                      webSiteInfoItem: webSiteInfoItem);
                                },
                                title: item.bookmark.name,
                                image: item.bookmark.logo);
                          })),
                if (provider.isLoading)
                  Container(
                      margin: const EdgeInsets.only(left: 20, top: 10),
                      padding: const EdgeInsets.only(top: 8, bottom: 2),
                      height: 78.w,
                      child: ListView.builder(
                          itemCount: 5,
                          physics: NeverScrollableScrollPhysics(),
                          scrollDirection: Axis.horizontal,
                          itemBuilder: (BuildContext context, int index) {
                            return DAppTopiItemSkeleton();
                          })),
                if (!provider.isLoading && provider.hotList.length == 0)
                  DAppEmpty(title: 'Empty data')
              ],
            )
          ],
        );
      }),
    );
  }
}
